package 贪心;

/**
 * @ClassName _860柠檬水找零
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/12/21 20:52
 * Version 1.0
 **/
public class _860柠檬水找零 {
    public boolean lemonadeChange(int[] bills) {
        int num5 = 0, num10 = 0, num20 = 0;
        for(int i = 0; i < bills.length; i++){
            switch (bills[i]){
                case 5:
                    num5++;
                    break;
                case 10:
                    num10++;
                    if(num5 <= 0){
                        return false;
                    }else {
                        num5--;
                    }
                    break;
                case 20:
                    num20++;
                    if(num10 >= 1 && num5 >= 1){
                       num10--;
                       num5--;
                    }else if(num5 >= 3){
                        num5 = num5 - 3;
                    }else {
                        return false;
                    }
                    break;
            }

        }
        return true;
    }
}
